
#include "../include/nosie.glsl"

attribute vec3 spritePos;

uniform float uPercent;
varying vec2 vUv;
varying float vPosX;
varying float vOffsetX;
varying vec3 vPositionWS;

void main() {
    vec4 transformed = vec4(position, 1.0);

    vPositionWS = vec3(modelMatrix * transformed);
    vUv = uv;

    vPosX = mix(-6., 3., uPercent) + abs(random21(spritePos.xz)) * 2.2;
    vOffsetX = 1. - clamp(spritePos.x - vPosX, 0., 1.);

    vec3 dir = normalize(mix(normalize(normal), normalize(cameraPosition - vec3(0., 1.5, 0.)), 0.95));
    transformed.xyz += dir * length(cameraPosition) * (1. - vOffsetX);

    gl_Position = projectionMatrix * modelViewMatrix * transformed;
}